//app.js
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => { 
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
  },
  getUserInfo: function (cb) {
    var that = this
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },
  formDate:function(date){
    var year=date.getFullYear();
    var month = date.getMonth()+1;
    var day = date.getDate();
    var h = date.getHours();
    var m = date.getMinutes();
    if (month<10){
      month = '0' + month;
    }
    return year + '-' + month + '-' + day+' '+h+':'+m
  },
  //多张图片上传
  uploadimg: function (data) {
    wx.showToast({
      icon: "loading",
      title: "正在上传"
    })
    var that = this,
    _this = data.globalkey,
    i=data.i ? data.i : 0,//当前上传的哪张图片
    success=data.success ? data.success : 0,//上传成功的个数
    fail=data.fail ? data.fail : 0;//上传失败的个数
    wx.uploadFile({
      url: data.url,
      filePath: data.path[i],
      name: 'file',//这里根据自己的实际情况改
      formData: null,//这里是上传图片时一起上传的数据
      success: (resp) => {
        success++;//图片上传成功，图片上传成功的变量+1
        data.tag == 0 ? data.realpath.push(JSON.parse(resp.data).data[0]) : data.realpath.splice(data.oIndex, 1, JSON.parse(resp.data).data[0]);
      },
      fail: (res) => {
        fail++;//图片上传失败，图片上传失败的变量+1
      },
      complete: (res) => {
        i++;//这个图片执行完上传后，开始上传下一张
        if (i == data.path.length) {   //当图片传完时，停止调用 
          _this.setData({
            [data.showkey]: data.realpath,
            [data.key]: data.realpath.join(",")
          }) 
          _this.changeValue();
          wx.hideToast();
        } else {//若图片还没有传完，则继续调用函数
          data.i = i;
          data.success = success;
          data.fail = fail;
          that.uploadimg(data);
        }
      }
    });
  },
  globalData: {
    userInfo: {},
    bottabData: [
      { icon: 'icon-shouye', txt: '首页', current: false, url: '/pages/home/home' },
      { icon: 'icon-fabu', txt: '发布', current: false },
      { icon: 'icon-xiaoxi', txt: '消息', current: false, url: '/pages/message/message' },
      { icon: 'icon-wode', txt: '我的', current: false, url: '/pages/wholeMine/wholeMine' }
    ],
    bottabDataForPpsj:[
      { icon: 'icon-shouye', txt: '首页', current: false, url: '/pages/brandBusiness/brandBusiness' },
      { icon: 'icon-fujin', txt: '附近', current: false, url: '/pages/near/near'  },
      { icon: 'icon-fabu', txt: '入驻', current: false, url: '/pages/seller/seller' },
      { icon: 'icon-gouwuche', txt: '购物车', current: false, url: '/pages/shopCart/shopCart'  },
      { icon: 'icon-wode', txt: '我的', current: false, url: '/pages/shopMine/shopMine' }
    ],
    bottabForPpsjindex: [
      { icon: 'icon-shouye', txt: '店铺', current: false, url: '/pages/shopIndex/shopIndex' },
      { icon: 'icon-fenlei', txt: '分类', current: false, url: '/pages/classify/classify' }
    ],
    bottabDataForSfc: [
      { icon: 'icon-shouye', txt: '首页', current: false, url: '/pages/freeRideHome/freeRideHome' },
      { icon: 'icon-fabu', txt: '发布', current: false, url: '/pages/publish/publish'},
      { icon: 'icon-wode', txt: '我的', current: false, url: '/pages/carMine/carMine' }//pages/personForCar/personForCar?isWholeMine=true
    ],
    bottabDataForFwzs: [
      { icon: 'icon-shouye', txt: '首页', current: false, url: '/pages/houseRenting/houseRenting' },
      { icon: 'icon-wode', txt: '我的', current: false, url: '/pages/fwzsMine/fwzsMine' }
    ],
    bottabDataForXq: [
      { icon: 'icon-shouye', txt: '首页', current: false, url: '/pages/blindHome/blindHome' },
      { icon: 'icon-wode', txt: '我的', current: false, url: '/pages/blindMine/blindMine' }
    ],
    bottabDataForZp: [
      { icon: 'icon-shouye', txt: '首页', current: false, url: '/pages/recruitHome/recruitHome' },
      { icon: 'icon-wode', txt: '我的', current: false, url: '/pages/recruitMine/recruitMine' }
    ],
    fbList: [
      { img: 'ic_people_looking_for_cars@2x.png', title: '顺风车', url: '/pages/publish/publish?title=顺风车&index='},
      { img: 'ic_activity@2x.png', title: '活动', url: '/pages/releaseAct/releaseAct'},
      { img: 'ic_brand_marketers@2x.png', title: '商品', url: ''},
      { img: 'ic_recruitment@2x.png', title: '工作', url: '/pages/recruitMine/recruitMine'},
      { img: 'ic_house_lease@2x.png', title: '房屋', url: '/pages/changecity/changecity?tag=true' },
      { img: 'ic_second_hand_spare@2x.png', title: '二手闲置', url: '/pages/secondPublish/secondPublish' },
      { img: 'dexk@2x.png', title: '信息台', url: '/pages/infoDeskPulish/infoDeskPulish' }
      ],
      openId:"wx698762ce296d30f8",
      imageUrl: 'https://www.yisou100.com/upload/image/gangyue/',
      uploadUrl:'http://huabangyun.oss-cn-hangzhou.aliyuncs.com/',
      httpApiImg: 'http://122.112.243.164:8080',
      // httpApiCar: 'https://www.yisou100.com/hd/',

      // httpApiCar: 'http://49.4.65.183:8080/gangyue/',
      // httpApiCar: 'http://20391e20d3.51mypc.cn/gangyue/',

      // httpApiCar: 'http://49.4.65.183:8080/gangyue/',
      // httpApiCar: 'http://gangue.crmhby.com/gangyue/',
      httpApiCar: 'https://www.yisou100.com/gangyue/',
      // httpApiCar: 'http://192.168.1.239:8080/',
      // httpApiSfc: 'https://www.yisou100.com/sfc/',

      // httpApiCar: 'http://192.168.1.250:8080/gangyue/', // tsy
      // httpApiCar: 'http://192.168.1.239:8080/',  // zs


      httpApi: 'https://www.yisou100.com/gangyue/',
  }
})